Repository navigation
fix(studio): a timeline clip click asks the source about its layer once - #8752
Conversation
Edit accuracy: accurate 273 (base branch 271), smooth 51 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
jrusso1020
left a comment
There was a problem hiding this comment.
Requesting changes at 209d846a630319e77beaa218f168fa94a2f362eb. The code is fine, but the PR turns the required file-size check red.
File size check fails with packages/studio/src/hooks/useDomSelection.ts has 628 lines (max 600). The file is 587 lines on main, and this PR adds buildTimelineSelection and sharingRunningBuilds (net +41). The fix is to move those two module-level helpers, and their two types, into a sibling module such as hooks/timelineSelectionBuild.ts and import them. They already take everything they need as arguments, so the move is mechanical.
Everything else from my review still holds:
- Red-first. With main's
useDomSelection.ts, both cases of "asks the source once when a clip click and the timeline's sync select the same clip" fail withexpected [...] to have a length of 1 but got 2. At the head, 3 files and 50 tests pass. - Sharing. It shares only while a build is running, keyed by clip key and iframe. The entry is removed on settle, and a new iframe never shares an older build. Every caller uses the result as the clip's selection to commit through.
I'll approve once the split is pushed and CI is green.
Need: yes · Size: right in substance, but over the per-file line cap · Reuse: same build body · Simpler: n/a · Structure: move the helpers out to fit the cap
Risk: low
— Rames
…side the selection hook
jrusso1020
left a comment
There was a problem hiding this comment.
Approve at d13f4d25d0006c4dcd250449ebc953fa6d054fc5. This resolves my change request.
buildTimelineSelection, sharingRunningBuilds and their two types moved into hooks/timelineSelectionBuild.ts. Across the two files, the only lines that differ between 209d846a and this head are two added export keywords and the moved imports. Every other line is identical. useDomSelection.ts is now 566 lines, under the 600 cap.
My earlier review stands:
- Red-first. With main's code, both "asks the source once…" cases fail with
length of 1 but got 2. - Sharing. A build is shared only while it is running, keyed by clip and iframe, and the entry is removed when it settles.
This approval is gated on CI green at this head.
Need: yes · Size: right · Reuse: same build body · Simpler: none · Structure: good, the helpers sit beside the hook
Risk: low
— Rames
What
Clicking a clip in the timeline now builds its canvas selection once and asks the source file about that layer once. Before, it did both twice.
Why
A clip click starts building the canvas selection (
handleTimelineElementSelect). It also changes the timeline selection, which makesuseTimelineSelectionPreviewSyncbuild the same clip's selection again: it compares against the canvas selection, which isn't set yet while the first build runs. Both builds end inexistsInSourceFile, so the source probe ran twice for one click.In a same-origin preview both probes fall in the same tick, so
probeSourceElementsends one request carrying the same target twice. In a sealed preview each build first waits on the frame's answer, so the two probes go as two separatePOST .../file-mutations/probe-elementsrequests, along with two lookups over the frame's port. On published 0.9.91 (hyperframes preview), selecting a clip by the timeline gave 2 probe requests per selection sealed and 1 unsealed, in every run.Async stacks for the two probes (v0.9.91, Studio dev server, a click on a clip, both modes):
onClick(TimelineLaneClip) →handleTimelineElementSelect→buildDomSelectionForTimelineElement→existsInSourceFileuseTimelineSelectionPreviewSynceffect →syncSelection→resolveSelectionsForIds→buildDomSelectionForTimelineElement→existsInSourceFileRelated work
Refs #7846 (Studio's preview sealed by default): a sealed preview made more requests than a regular one for the same click.
How
hooks/useDomSelection.ts:buildDomSelectionForTimelineElementnow hands a clip's build that is still running to anyone who asks for the same clip in the same frame meanwhile (sharingRunningBuilds). Once the build settles, the next ask builds afresh.buildTimelineSelection), so the hook's complexity stays where it was.Test plan
asks the source once when a clip click and the timeline's sync select the same clipinsrc/components/editor/previewPointerTargets.test.ts, for both a sealed and a same-origin frame. It failed on main withexpected [...] to have a length of 1 but got 2: two probed targets for one selection.useDomSelection.test.ts,useDomSelectionSelectionGuards.test.ts,useTimelineSelectionPreviewSync.test.tsx,EditorShell.selectionSync.test.tsx,previewSelection.test.ts,LayersPanel.opaque.test.ts,useDomEditSession.test.tsx, green. The covering Studio test files the gate picked, green. tsc, Fallow and the pre-push hooks clean.console.traceonprobeSourceElement, a click on a clip in the timeline, both modes (frame origin read in-run):http://localhost:5431)null)No visible change
The selection a clip click makes is the same; only the requests behind it drop. Nothing is drawn differently, so there is no capture to compare.